package cn.iocoder.yudao.module.book.dal.mysql.community;

import java.util.*;

import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.book.dal.dataobject.community.PostTopicsDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 动态话题关联 Mapper
 *
 * @author system
 */
@Mapper
public interface PostTopicsMapper extends BaseMapperX<PostTopicsDO> {

    /**
     * 根据动态ID查询话题列表
     */
    default List<PostTopicsDO> selectByPostId(Long postId) {
        return selectList(new LambdaQueryWrapperX<PostTopicsDO>()
                .eq(PostTopicsDO::getPostId, postId));
    }

    /**
     * 根据话题ID查询动态列表
     */
    default List<PostTopicsDO> selectByTopicId(Long topicId) {
        return selectList(new LambdaQueryWrapperX<PostTopicsDO>()
                .eq(PostTopicsDO::getTopicId, topicId));
    }

    /**
     * 根据动态ID删除关联
     */
    default int deleteByPostId(Long postId) {
        return delete(new LambdaQueryWrapperX<PostTopicsDO>()
                .eq(PostTopicsDO::getPostId, postId));
    }

    /**
     * 批量插入动态话题关联
     */
    int insertBatch(@Param("postTopics") List<PostTopicsDO> postTopics);

}
